package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.adapters.old.PhoneNumberPaymentDetailAdapter
import com.hinnotek.amoeba.bean.old.CompanyPhonePayByIdBean
import com.hinnotek.amoeba.databinding.ActivityPhoneNumberPaymentDetailBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.PhoneViewModel
import com.lee.common.network.net.ObserverState

class PhoneNumberPaymentDetailActivity : BaseActivity<ActivityPhoneNumberPaymentDetailBinding>() {

    private var mAdapter: PhoneNumberPaymentDetailAdapter? = null
    val viewModel by viewModels<PhoneViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        setTitle("手机号缴费申请")

        setContentView(R.layout.activity_phone_number_payment_detail)
    }

    override fun initVew() {
        val manager = LinearLayoutManager(mContext)
        manager.orientation = RecyclerView.VERTICAL
        bindingView.rlvPnpDetail.layoutManager = manager
        bindingView.rlvPnpDetail.adapter = PhoneNumberPaymentDetailAdapter().also { mAdapter = it }
    }

    override fun setData() {
        val companyPhonePayId = intent.getIntExtra("companyPhonePayId", 0)
        getCompanyPhonePayById(companyPhonePayId)
    }

    /**
     * app端查询单个手机号缴费申请详情接口
     */
    fun getCompanyPhonePayById(companyPhonePayId: Int) {
        val customDialog = CustomDialog(mContext, "正在加载...")
        customDialog.show()
        viewModel.getCompanyPhonePayById(companyPhonePayId)
            .observe(this, object : ObserverState<CompanyPhonePayByIdBean>() {
                override fun onDataChange(data: CompanyPhonePayByIdBean) {
                    bindingView.tvPnpChooseAmoeba.text = data.orgName
                    bindingView.tvPnpTotal.text = data.payMoney
                    bindingView.tvPnpApplicant.text = data.createUser
                    bindingView.tvPnpApprover.text = data.approvalUser
                    bindingView.tvPnpCc.text = data.sendUser
                    if (data.approvalState == 1) {
                        bindingView.tvApproverStatus.text = "已申请"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.black))
                    } else if (data.approvalState == 2) {
                        bindingView.tvApproverStatus.text = "已同意"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_btn_green_normal_color))
                    } else if (data.approvalState == 3) {
                        bindingView.tvApproverStatus.text = "已拒绝"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_config_color_red))
                    }
                    mAdapter?.setList(data.companyPhones)
                    super.onDataChange(data)
                }
                override fun onError(msg: String?, code: Int) {
                    customDialog.dismiss()
                    ToastUtils.showShort(mContext, msg)
                    super.onError(msg, code)
                }
            })
    }
}